/*
 * @Author: Songjq
 * @Date: 2021-08-13 16:38:30
 * @Desscription:
 */
import checkPermission from "@/utils/permission";
export default {
    data() {
        return {
            pageParam: {
                // 页码
                page: 1,
                // 每页数据条数
                size: 10
            },
            total: 0,
            pageSizes: [10, 20, 30, 50]
        };
    },
    methods: {
        checkPermission,
        /**
         * @Author: Songjq
         * @Date: 2021-12-19 17:43:18
         * @Fn: 切换展示条目数
         * @param {*} val
         */
        handleSizeChange(val) {
            this.pageParam.size = val;
            this.init();
        },

        /**
         * @Author: Songjq
         * @Date: 2021-12-19 17:43:41
         * @Fn: 切换页码
         * @param {*} val
         */
        handleCurrentChange(val) {
            this.pageParam.page = val;
            this.init();
        },

        /**
         * @Author: Songjq
         * @Date: 2021-12-19 18:20:58
         * @Fn: 重置分页信息
         */
        resetPage() {
            this.pageParam.page = 1;
            this.init();
        },

        // 验证检索字段，不得为特殊字符，不能少于2个字符
        verifyKeyword(keyword) {
            var regEn = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im;
            var regCn = /[·！#￥（——）：；“”‘、，|《。》？、【】[\]]/im;
            let isNotGo = false;
            let str = "";
            if (regEn.test(keyword) || regCn.test(keyword)) {
                str = "名称不能包含特殊字符";
                isNotGo = true;
            }

            if (keyword && keyword.length > 0 && keyword.length < 2) {
                str = "检索内容不得少于2个字符";
                isNotGo = true;
            }

            return {
                isNotGo: isNotGo,
                tips: str
            };
        },

        /**
         * @Author: Songjq
         * @Date: 2021-12-15 00:11:25
         * @Fn: 获取公告类型中文字段
         */
        getPubTypeStr(type, options, value = "value", label = "label") {
            let str = "";
            options.forEach(val => {
                if (val[value] == type) {
                    str = val[label];
                }
            });
            return str;
        },

        /**
         * @Author: Songjq
         * @Date: 2022-01-04 09:32:07
         * @Fn: 通过父级ID 拼接组织树
         */
        getChildrens(nodes, pid, arr) {
            nodes.forEach(val => {
                if (val.orgId === pid) {
                    val.children = arr;
                } else if (val.children && val.children.length > 0) {
                    this.getChildrens(val.children, pid, arr);
                }
            });
        }
    }
};